* Clearing
CLEAR WINDOW
CLEAR
CLEAR ALL
CLEAR POPUP
CLOSE ALL
* Settings
PUBLIC lOK, cOldTalk
PUBLIC cHomeDirectory, cAgendaFile, cInfoFile
lOK = .T.
DO initializare
* Execute
IF lOK
   DO mainmenu.mpr
   READ EVENTS
ENDIF
* Clearing
DO iesire
*
PROCEDURE initializare
   ON ERROR DO errormanager
   ON SHUTDOWN CLEAR EVENTS
   DO tbsave
   cOldTalk = SET("TALK")
   SET TALK OFF
   cHomeDirectory = JUSTPATH(SYS(16,0))
   SET DEFAULT TO (cHomeDirectory)
   DO citireini
   IF lOK
      DO openfiles
   ENDIF
   *
PROCEDURE citireini
   IF FILE(cHomeDirectory+"\agenda.ini")
      nHandle = FOPEN(cHomeDirectory+"\agenda.ini", 0)
      cAgendaFile = ALLTRIM(FGETS(nHandle))
      cInfoFile = ALLTRIM(FGETS(nHandle))
   ELSE
      nHandle = FCREATE(cHomeDirectory+"\agenda.ini")
      cAgendaFile = cHomeDirectory+"\data\agenda.dbf"
      cInfoFile = cHomeDirectory+"\data\informatii.dbf"
      = FPUTS(nHandle, cAgendaFile)
      = FPUTS(nHandle, cInfoFile)
   ENDIF
   =FCLOSE(nHandle)
   *
PROCEDURE scriereini
   IF FILE(cHomeDirectory+"\agenda.ini")
      DELETE FILE (cHomeDirectory+"\agenda.ini")
   ENDIF
   nHandle = FCREATE(cHomeDirectory+"\agenda.ini")
   = FPUTS(nHandle, cAgendaFile)
   = FPUTS(nHandle, cInfoFile)
   = FCLOSE(nHandle)
   *
PROCEDURE openfiles
   IF FILE(cAgendaFile)
      USE (cAgendaFile) ALIAS agenda IN 0 ORDER numelung
   ELSE
      MESSAGEBOX("Lipseste fisierul agenda.dbf"+CHR(13)+;
         "Apasati orice tasta...", 16,;
         "Eroare")
      lOK = .F.
      RETURN
   ENDIF
   *
   IF FILE(cInfoFile)
      USE (cInfoFile) ALIAS informatii IN 0 ORDER codpers
   ELSE
      MESSAGEBOX("Lipseste fisierul informatii.dbf"+CHR(13)+;
         "Apasati orice tasta...", 16,;
         "Eroare")
      lOK = .F.
      RETURN
   ENDIF
   *
   IF FILE(cHomeDirectory+"\data\localitati.dbf")
      USE (cHomeDirectory+"\data\localitati") ALIAS localitati IN 0 ORDER cod_l
   ELSE
      MESSAGEBOX("Lipseste fisierul localitati.dbf"+CHR(13)+;
         "Apasati orice tasta...", 16,;
         "Eroare")
      lOK = .F.
      RETURN
   ENDIF
   *
   IF FILE(cHomeDirectory+"\data\judete.dbf")
      USE (cHomeDirectory+"\data\judete") ALIAS judete IN 0 ORDER cod_j
   ELSE
      MESSAGEBOX("Lipseste fisierul judete.dbf"+CHR(13)+;
         "Apasati orice tasta...", 16,;
         "Eroare")
      lOK = .F.
      RETURN
   ENDIF
   *
   IF FILE(cHomeDirectory+"\data\tari.dbf")
      USE (cHomeDirectory+"\data\tari") ALIAS tari IN 0 ORDER cod_t
   ELSE
      MESSAGEBOX("Lipseste fisierul tari.dbf"+CHR(13)+;
         "Apasati orice tasta...", 16,;
         "Eroare")
      lOK = .F.
      RETURN
   ENDIF
   *
   SELECT agenda
   GO TOP
   SET RELATION TO codpers INTO informatii
   SET SKIP TO informatii
   SET RELATION TO cod_l INTO localitati ADDITIVE
   SET RELATION TO cod_j INTO judete ADDITIVE
   SET RELATION TO cod_t INTO tari ADDITIVE
   *
PROCEDURE iesire
   DO tbrest
   ON SHUTDOWN
   SET TALK &cOldTalk
   CLEAR WINDOW
   CLEAR
   CLEAR ALL
   CLOSE ALL
   SET SYSMENU TO DEFAULT
   *
PROCEDURE errormanager
   MESSAGEBOX("Programul se termina din cauza unei erori"+CHR(13)+;
      MESSAGE() + CHR(13) + ;
      "Apasati orice tasta...", 16,;
      "Eroare")
   CLEAR events
   DO iesire
   QUIT
   *
   ****************************************************
   * This routine saves the status of the system      *
   * toolbars in the global array gaTbsets. Call the  *
   * procedure TBREST to restore the system toolbars  *
   * to their saved state                             *
   ****************************************************
PROCEDURE tbsave
   PUBLIC gaTbsets
   PRIVATE lnCnt,lnTB
   lnTB=11

   DIMENSION gaTbsets[lnTB,2]

   gaTbsets[1,1]="Color Palette"
   gaTbsets[2,1]="Database Designer"
   gaTbsets[3,1]="Form Controls"
   gaTbsets[4,1]="Form Designer"
   gaTbsets[5,1]="Layout"
   gaTbsets[6,1]="Print Preview"
   gaTbsets[7,1]="Query Designer"
   gaTbsets[8,1]="Report Controls"
   gaTbsets[9,1]="Report Designer"
   gaTbsets[10,1]="Standard"
   gaTbsets[11,1]="View Designer"

   FOR lnCnt=1 TO lnTB
      IF WEXIST(gaTbsets(lnCnt,1))
         gaTbsets(lnCnt,2)=.T.
         HIDE WINDOW (gaTbsets(lnCnt,1))
      ELSE
         gaTbsets(lnCnt,2)=.F.
      ENDIF
   ENDFOR

   RETURN
   *
   *******************************************************
   * This routine restores the system toolbars to        *
   * their saved state as defined in the array gaTbsets. *
   * Save this as TBREST.PRG                             *
   *******************************************************
PROCEDURE tbrest

   PRIVATE lnCnt

   FOR lnCnt=1 TO ALEN(gaTbsets,1)
      IF gaTbsets(lnCnt,2)
         SHOW WINDOW (gaTbsets(lnCnt,1))
      ENDIF
   ENDFOR
   RETURN


